<?php

/**
 * content actions.
 *
 * @package    testprj
 * @subpackage content
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class contentActions extends sfActions
{
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
	public function executeIndex(sfWebRequest $request)
	{
		$this->forward('default', 'module');
	}

	public function executeShow(sfWebRequest $request)
	{
		$today = getdate();
		$this->hour = $today['hours'];
//		$article = new Article();
//		$article->setTitle('test title number two');
//		$article->setContent('hello to the world');
//		
		$article = Doctrine_Core::getTable('Article')->find(2);
		$comment = new Comment();
		$comment->setAuthor('bb');
		$comment->setContent('hehehehe1111');
		$comment->setArticle($article);
		
		$comment->save();
		
//		$article->save();

	}

	public function executeUpdate(sfWebRequest $request)
	{
		$name = $request->getParameter('fullname');
		$this->name = $name . 'show';
	}
	
	public function executeTestDb()
	{
		$article = Doctrine_Core::getTable('Article')->find(2);
		$this->title = $article->getTitle(0);
		
//		$q = Doctrine_Core::getTable('Comment')
//					->createQuery('c')
//					->where('c.author = ?', 'steve')
//					->orderBy('c.created_at ASC');
//		$comments = $q->execute();
		$comments = $article->getComments();
		$this->comments = $comments;			
		
	}
	
	public function executeNewArticle(sfWebRequest $request)
	{
		if (!$request->isMethod('post'))
		{
			$this->form = new ArticleForm();
		}
		else 
		{
			$this->form = new ArticleForm();
			$this->form->bind($request->getParameter('article'));
			if ($this->form->isValid())
			{
				$this->form->save();
				$this->result = 'success';
			}
			
		}
	}
	
	public function executeNewComment(sfWebRequest $request)
	{
	if (!$request->isMethod('post'))
		{
			$this->form = new CommentForm();
		}
		else 
		{
			$this->form = new CommentForm();
			$this->form->bind($request->getParameter('comment'));
			if ($this->form->isValid())
			{
				$this->form->save();
				$this->result = 'success';
			}
			
		}
	}
}
